var count=1;
var privatecount=1;
var upload1;
var upload4;

var reportstr="举报他:"+"<input type='text' name='beReportName' id='beReportName' readonly='readonly'/><br/>"+
	"举报情况:<textarea rows='10' cols='20' name='reportContent' id='reportContent'></textarea><br/>";
var privatetalkstr="<div id='privatemessage'>"+ "发给：<input type='text' name='toName' id='toName' readonly='readonly'/><br/>"+
		          	"内容：<textarea rows='10' cols='20' name='messagContent' id='messagContent'></textarea><br/>"+ "</div>"+
				   "<div id='privatefiles'>"+"<div style='padding-left: 5px;'>"+ "<span id='spanButtonPlaceholder1'></span>"+
				   "<input id='btnCancel1' type='button' value='Cancel Uploads' onclick='cancelQueue(upload1)' disabled='disabled' style='margin-left: 2px; height: 22px; font-size: 8pt;' />"+
					 "<br />"+"</div>"+ "<div class='fieldset flash' id='fsUploadProgress1' style='float: center;'>"+ "<span class='legend'>文件上传</span>"+"</div>"+"</div>";
var customuploadfilestr="<div id='customuploadfilestrdiv'>"+
							"<span id='spanButtonPlaceholder4'></span>"+
							"<input id='btnCancel4' type='button' value='Cancel Uploads' onclick='cancelQueue(upload4)' disabled='disabled' style='margin-left: 2px; height: 22px; font-size: 8pt;' />"+
							"<div class='fieldset flash' id='fsUploadProgress4' style='float: center;'>"+
								"<span class='legend'>文件上传</span>"+
							"</div>"+
						"</div>";

function picturemouseover(){
	
	$("#fangxiangdiv").fadeIn(100);
}
function ShowMoreComment(Customid){
	alert(Customid);
	window.open("ShareInfo?_id="+Customid);
}
function picturemouseout(){
	//alert("sa");
	$("#fangxiangdiv").hide();
}
function clickLeftPic(){
	$("#myShowCar_id").attr("src","img/test5.jpg");
	//alert("left");
}
function clickRightPic(){
	$("#myShowCar_id").attr("src","img/test3.jpg");
}

function initSWFUpload4(customId,toName){
	upload4= new SWFUpload({
			//提交路径
			upload_url: "CustomUploadFileAction",
			//向后台传递额外的参数
			 post_params: {"customId":customId,"toName":toName},
			//上传文件的名称
			file_post_name: "files",
			
			// 下面自己按照字面意思理解
			file_size_limit : "102400",	// 100MB
			file_types : "*.txt;*.gif",
			file_types_description : "txt模式和JPG",
			file_upload_limit : "10",
			file_queue_limit : "0",

			// 事件处理
			file_dialog_start_handler : fileDialogStart,
			file_queued_handler : fileQueued,
			file_queue_error_handler : fileQueueError,
			file_dialog_complete_handler : fileDialogComplete,
			upload_start_handler : uploadStart,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccess,
		    upload_complete_handler : uploadComplete,

			// 按钮的处理
			button_image_url : "swfupload/XPButtonUploadText_61x22.png",
			button_placeholder_id : "spanButtonPlaceholder4",
			button_width: 61,
			button_height: 22,
			
			// Flash Settings
			flash_url : "swfupload/swfupload.swf",
			custom_settings : {
				progressTarget : "fsUploadProgress4",
				cancelButtonId : "btnCancel4"
			},
			debug: false
		});
	
}

function showfriendshareothercomment(customId){
	//alert(customId);
	$("#"+customId+"friendshareothercomment").show(500,function(){
		$("#"+customId+"friendshareothercomment").click(function(){
			$("#"+customId+"friendshareothercomment").hide();
		});
	});
}

function showfriendorderothercomment(customId){
	$("#"+customId+"friendorderothercomment").show(500,function(){
		$("#"+customId+"friendorderothercomment").click(function(){
			$("#"+customId+"friendorderothercomment").hide();
		});
	});
}

function CustomUploadFiledialog(customId,toName){
	alert(customId);
	 alert(toName);
	 $("#customUploadFiledialog").dialog({
		 resizable:false,
   	  //show: "slide",
   	  autoOpen:true,
         module : true,
         width:600,
         height:250,
         position:[getLeft(600),getTop(250)],//定位
         title: "给他发个文件看",
         open:function(){
       		  $("#customUploadFiledialog").html(customuploadfilestr).fadeIn();
       		  initSWFUpload4(customId,toName);
         },
         close: function(event, ui){
       	  
         },
         buttons:{
       	  '提交' :function(){
       		  if(upload4.getStats().files_queued === 0){
       			  alert("无任何文件，您先选择文件");
       		  }else{
       			  sendswf4();
       		      alert("发送成功");
       		      $(this).dialog('close');
       		  }
       	  },
       	  '取消':function(){
       		  $(this).dialog('close');
       	  }
         },
	 });
}

function sendCommentInOwnMessageByOrder(customId){
	var content=$("#"+customId+"dingzhicontent").val();
	if(content==null||content==""){
		$("#report_success").html("亲，请输入内容哦").dialog({
			autoOpen:true,
			width:300,
			height:180,
			position:[getLeft(300),getTop(180)],
			buttons:{
				确定:function(){
					$(this).dialog("close");
				}
			}
		});
	}else{
		$.post('CommentFriendCustomsByAjAxAction',{'customid':customId,'textContent':content},function(data){
		 	if(data=="success"){
		 		$("#"+customId+"dingzhicontent").val("");
		 		$.getJSON('GetTheLastCommentByCustomId',{'CustomId':customId},function(data){
		 			$("."+customId+"Comment").html("");
		 			$("."+customId+"Comment").append("<a href='getFriendOwnMessageAction?uname="+data.comment.userName+"'>"+data.comment.userName+"</a>:"+data.comment.commentContent+data.comment.commentTime+"<br/>");
		 			$("."+customId+"Comment").append("<span style='float: right'><a href='javascript:void(0);' onclick='openDialog(\""+data.comment.userName+"\")'>私聊</a>|<a href='javascript:void(0);' onclick='openReportDialog(\""+data.comment.userName+"\","+data.comment.commentId+")'>举报</a></span><br/>");
		 			$("."+customId+"comemntcount").html(data.commentCountbycustomid);
		 			$("."+customId+"friendothercomment").append("<a href='getFriendOwnMessageAction?uname="+data.comment.userName+"'>"+data.comment.userName+"</a>:"+data.comment.commentContent+data.comment.commentTime+"<br/>");
		 			$("."+customId+"friendothercomment").append("<span style='float: right'><a href='javascript:void(0);' onclick='openDialog(\""+data.comment.userName+"\")'>私聊</a>|<a href='javascript:void(0);' onclick='openReportDialog(\""+data.comment.userName+"\","+data.comment.commentId+")'>举报</a></span><br/>");
		 		});
		 		$("#report_success").html("插入成功啦").dialog({
					autoOpen:true,
					width:300,
					height:180,
					position:[getLeft(300),getTop(180)],
					buttons:{
						确定:function(){
							$(this).dialog("close");
						}
					}
				});
		 	}else{
		 		$("#"+customId+"dingzhicontent").val("");
		 		$("#report_success").html("插入失败了，哎").dialog({
					autoOpen:true,
					width:300,
					height:180,
					position:[getLeft(300),getTop(180)],
					buttons:{
						确定:function(){
							$(this).dialog("close");
						}
					}
				});
		 	}
	 });
	}
}

function getCurrentDate(){
	var new_date=new Date();
	var dateStr=new_date.getFullYear()+"/"+new_date.getMonth()+"/"+new_date.getDate()+
	" "+new_date.getHours()+":"+new_date.getMinutes()+":"+new_date.getMinutes();
	return dateStr;
	// example 2012-3-3 12:45:12
}

function sendCommentInOwnMessageByShare(customId){
	var content=$("#"+customId+"sharecontent").val();
	if(content==null||content==""){
		$("#report_success").html("亲，请输入内容哦").dialog({
			autoOpen:true,
			width:300,
			height:180,
			position:[getLeft(300),getTop(180)],
			buttons:{
				确定:function(){
					$(this).dialog("close");
				}
			}
		});
	}else{
		$.post('CommentFriendCustomsByAjAxAction',{'customid':customId,'textContent':content},function(data){
		 	if(data=="success"){
		 		$("#"+customId+"sharecontent").val("");
		 		$.getJSON('GetTheLastCommentByCustomId',{'CustomId':customId},function(data){
		 			$("."+customId+"Comment").html("");
		 			$("."+customId+"Comment").append("<a href='getFriendOwnMessageAction?uname="+data.comment.userName+"'>"+data.comment.userName+"</a>:"+data.comment.commentContent+data.comment.commentTime+"<br/>");
		 			$("."+customId+"Comment").append("<span style='float: right'><a href='javascript:void(0);' onclick='openDialog(\""+data.comment.userName+"\")'>私聊</a>|<a href='javascript:void(0);' onclick='openReportDialog(\""+data.comment.userName+"\","+data.comment.commentId+")'>举报</a></span><br/>");
		 			$("."+customId+"comemntcount").html(data.commentCountbycustomid);
		 			$("."+customId+"friendothercomment").append("<a href='getFriendOwnMessageAction?uname="+data.comment.userName+"'>"+data.comment.userName+"</a>:"+data.comment.commentContent+data.comment.commentTime+"<br/>");
		 			$("."+customId+"friendothercomment").append("<span style='float: right'><a href='javascript:void(0);' onclick='openDialog(\""+data.comment.userName+"\")'>私聊</a>|<a href='javascript:void(0);' onclick='openReportDialog(\""+data.comment.userName+"\","+data.comment.commentId+")'>举报</a></span><br/>");
		 			
		 		});
		 		$("#report_success").html("插入成功啦").dialog({
					autoOpen:true,
					width:300,
					height:180,
					position:[getLeft(300),getTop(180)],
					buttons:{
						确定:function(){
							$(this).dialog("close");
						}
					}
				});
		 	}else{
		 		$("#"+customId+"sharecontent").val("");
		 		$("#report_success").html("插入失败了，哎").dialog({
					autoOpen:true,
					width:300,
					height:180,
					position:[getLeft(300),getTop(180)],
					buttons:{
						确定:function(){
							$(this).dialog("close");
						}
					}
				});
		 	}
	 });
	}
	 
}


function sendswf(){
	 upload1.startUpload();
}
function sendswf4(){
	 upload4.startUpload();
}
function initSWFUpload(){
	 upload1 = new SWFUpload({
			//提交路径
			upload_url: "PrivateTalkSWFUploadAction",
			//向后台传递额外的参数
			 post_params: {"toName" :$("#toName").val()},
			//上传文件的名称
			file_post_name: "file",
			
			// 下面自己按照字面意思理解
			file_size_limit : "102400",	// 100MB
			file_types : "*.txt;*.gif",
			file_types_description : "txt模式和JPG",
			file_upload_limit : "10",
			file_queue_limit : "0",

			// 事件处理
			file_dialog_start_handler : fileDialogStart,
			file_queued_handler : fileQueued,
			file_queue_error_handler : fileQueueError,
			file_dialog_complete_handler : fileDialogComplete,
			upload_start_handler : uploadStart,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccess,
		    upload_complete_handler : uploadComplete,

			// 按钮的处理
			button_image_url : "swfupload/XPButtonUploadText_61x22.png",
			button_placeholder_id : "spanButtonPlaceholder1",
			button_width: 61,
			button_height: 22,
			
			// Flash Settings
			flash_url : "swfupload/swfupload.swf",
			custom_settings : {
				progressTarget : "fsUploadProgress1",
				cancelButtonId : "btnCancel1"
			},
			// Debug Settings
			debug: false
		});
	
}

function getTop(height){
	var windowheight=window.innerHeight;
	return (windowheight-height)/2;
}
function getLeft(width){
	var windowwidth=window.innerWidth;
	return (windowwidth-width)/2;
}
/*function showothercomment(id){
			var _id=id+10000000000;
			document.getElementById(_id).style.display="";
		}*/
		function commentdivmouseout(id){
			document.getElementById(id).style.display="none";
		}
		/*function showothercommentshare(id){
			var _id=id+20000000000;
			document.getElementById(_id).style.display="";
		}*/
		function commentdivmouseoutshare(id){
			document.getElementById(id).style.display="none";
		}
		function showshare(){
			
			document.getElementById("dingzhiall_out").style.display="none";
			document.getElementById("shareall_out").style.display="block";
			document.getElementById("sharediv").className="myfriend_friendactivity_content_right_select_mymoney2";
			document.getElementById("dingzhidiv").className="myfriend_friendactivity_content_right_select_mymoney";
		}
		function showdingzhi(){
			document.getElementById("dingzhiall_out").style.display="";
			document.getElementById("shareall_out").style.display="none";
			document.getElementById("sharediv").className="myfriend_friendactivity_content_right_select_mymoney";
			document.getElementById("dingzhidiv").className="myfriend_friendactivity_content_right_select_mymoney2";
		}
		function addfirends(value){
			var value=document.getElementById("needaddfirendvalue").value;
			var url = "AddFriendsAction";
			if(value!=""&&value!=null){
				$.post(url,{addUser:value},function(data){//传入的值和返回来的值
						if(data =="true"){
							alert("已经加为好友");
							document.getElementById("addf").style.display="none";
							return data;
						}else if(data=="false"){
							alert("增加好友失败");
							return data;
						}
				});
			} 
		}
		
		
		
		
		$(function(){
			//$("a#showmylovecar").fancybox();
			$("a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});

			$("button").button();
			$("div.holder2").jPages({
	            containerID :"shareall",
				first: '首页',
				last: '尾页',
				previous: '上页',
				next: '下页',
	            perPage:2,
	            startPage:1,
	          /*	animation: 'wobble',*/
				/* keyBrowse: true, */
				callback:function(pages,items){
					items.showing.find("img").trigger("turnPage");
					items.oncoming.find("img").trigger("turnPage");
				}
          });
			$("#shareall_out").hide();
			$("div.holder").jPages({
	            containerID :"dingzhiall",
				first: '首页',
				last: '尾页',
				previous: '上页',
				next: '下页',
	            perPage:2,
	            startPage:1,
	          	/* animation: 'wobble', 有以下几种选择 flash bounce shake tada swing wobble wiggle pulse*/
				/* keyBrowse: true, */
				callback:function(pages,items){
					items.showing.find("img").trigger("turnPage");
					items.oncoming.find("img").trigger("turnPage");
				}
          });
          
          
           $("div.holder3").jPages({
	            containerID :"itemContainerc",
				first: '首页',
				last: '尾页',
				previous: '上页',
				next: '下页',
	            perPage:3,
	            startPage:1,
	          	/* animation: 'wobble', */
				/* keyBrowse: true, */
				callback:function(pages,items){
					items.showing.find("img").trigger("turnPage");
					items.oncoming.find("img").trigger("turnPage");
				}
          });
        });
       
		

		
		function openDialog(customName){
			var content="";
			 $("#register-form").dialog({
	        	  resizable:false,
	        	  show: "slide",
	        	  autoOpen:true,
	              module : true,
	              width:600,
	              height:450,
	              position:[getLeft(600),getTop(450)],//定位
	              title: "找他私聊下aaa",
	              open:function(){
	            	  /*if(privatecount==1){
	            		  $("#register-form").append(privatetalkstr).fadeIn();
	            		  privatecount=2;
	            	  }*/
	            	  $("#register-form").append(privatetalkstr).fadeIn();
	            	  $("#toName").val(customName);
	            	  setTimeout("initSWFUpload()",500);
	              },
	              close: function(event, ui){
	            	  $("#messagContent").val("");
	            	  $("#register-form").html("");
	              },
	              buttons:{
	            	  '提交' :function(){
	            		  content= $("#messagContent").val();
	            		  if(upload1.getStats().files_queued !== 0){
	            			  sendswf();
	            		  }else if(upload1.getStats().files_queued === 0){
	            				alert("file is null");
	            			  $.post('SwfSuccessToDateBase',{'toName':$("#toName").val(),'filesName':"",'messageContent':$("#messagContent").val()},function(data){
	            					if(data=="true"){
	            						$("#report_success").html("您的私聊已经发到").dialog({
	            							autoOpen:true,
	            							width:300,
	            							height:180,
	            							position:[getLeft(300),getTop(180)],
	            							buttons:{
	            								确定:function(){
	            									$(this).dialog("close");
	            									$("#register-form").dialog("close");
	            								}
	            							}
	            						});
	            					}else{
	            							alert("发送失败");
	            							$("#register-form").dialog("close");
	            					}
	            				});
	            			
	            		  }
	            	  },
	            	  '取消':function(){
	            		  $(this).dialog('close');
	            	  }
	              },
	        });
		}
		
      function openReportDialog(customName,commentId){
	        $( "#report-form").dialog({
	        	  resizable:false,
	        	  show: "slide",
	        	  autoOpen:true,
	              module : true,
	              width:600,
	              height:450,
	              position:[getLeft(600),getTop(450)],//定位
	              title: "我要举报他",
	              open:function(){
	            	  if(count==1){
	            		  $(this).append(reportstr).fadeIn();
	            		  count=2;
	            	  }
	            	  document.getElementById("reportContent").focus();
	            	  //document.getElementById("beReportName").value=customName;
	            	  $("#beReportName").val(customName);
	              },
	              close: function(event, ui){
	            	  $("#reportContent").val("");
	              },
			      buttons:{
				    '提交' : function() {
				    	var Content=document.getElementById("reportContent").value;
				    	if(Content==null||Content==""){
				    		alert("亲，您还没有输入举报的理由呢！");
				    	}else{
				    		$.post('SendReportByAjAxAction',{'beReportName':customName,'commentId':commentId,'reprotContent':Content},function(data){//传入的值和返回来的值
								if(data =="true"){
									$("#report_success").html("举报成功！我们会尽快处理").dialog({
										autoOpen:true,
										width:300,
										height:180,
										position:[getLeft(300),getTop(180)],
										buttons:{
											确定:function(){
												$(this).dialog("close");
											}
										}
									});
									$("#report-form").dialog('close');
									//return data;
								}else if(data=="false"){
									alert("举报失败");
									//return data;
								}
					    	});
				    	}
				    },'取消' :function(){
				    	$(this).dialog('close');
				    }
				 },
	        });
    }
      
      function openFileImage(){
	      	document.getElementById("upimage").click();
      }
      function openFile(){
	      	document.getElementById("ofile").click();
      }
      function openFileImage2(){
	      	document.getElementById("upimage2").click();
      }
      function openFile2(){
	      	document.getElementById("ofile2").click();
      }
      function selectNewFriend(){
      		var selectname=document.getElementById("selectNewFriend").value;
       		var f=document.getElementById("selectform");
      	if(selectname==""||selectname==null){
      		alert("不能为空");
      	}else{
      		$.post("CheckNameAction",{uname:selectname},function(data){
      			if(data=="true"){
      				f.action="getFriendOwnMessageAction";
      	      		f.submit();
      			}else{
      				alert("还没有这个用户哦！！");
      				$("#selectNewFriend").val("");
      			}
      		});
      	} 
      }
      
    
      function check(){
      		var val=document.getElementById("msgContent").value;
      		if(val==""||val==null){
      			alert("发送信息不能为空aaa");
      			//return false;
      		}else{
      			var oform=document.getElementById("msgform");
     			oform.submit();
      		}
      }
      function callbackMessage(msg){
    		if(msg=="success"){
    			document.getElementById("upimage").outerHTML = document.getElementById("upimage").outerHTML;  
    			document.getElementById("ofile").outerHTML = document.getElementById("ofile").outerHTML;  
    			$("#msgContent").val("");
    			$("#selectfilenamediv").html("");
    			alert("发送成功啦！！开心不");
    		}else{
    			$("#msgContent").val("");
    			$("#selectfilenamediv").html("");
    			alert("发送失败啦！！哎");
    		}
    	}
      function changeimageandfile(){
     	var c=document.getElementById("upimage").value;//获取文本控件的值，显示到页面
     	var ex=c.substring(c.indexOf(".")+1,c.length);
     	if(ex=="gif"||ex=="png"||ex=="jpg"||ex=="jpeg"){
     		$("#selectfilenamediv").html("上传的图片名为："+c);
     	}else{
     		alert("图片类型只能为gif或png或jpg或jpeg");
     		document.getElementById("upimage").outerHTML = document.getElementById("upimage").outerHTML;  
     	}
      }
      function changeupdatefile(){
    	  if(document.getElementById("upimage").value==""||document.getElementById("upimage").value==null){
    		  alert("您先选择上传的图片(gif或png或jpg或jpeg)，才能选择文件(cdr或ai或psd)！");
    	  }else{
    		    var d=document.getElementById("ofile").value;//获取文本控件的值，显示到页面
  	     		var ex=d.substring(d.indexOf(".")+1,d.length);
  	     		if(ex=="cdr"||ex=="ai"||ex=="psd"||ex=="txt"){
  	     			$("#selectfilenamediv").html($("#selectfilenamediv").html()+"<br/>"+"上传的文件名为："+d);
  	     		}else{
  	     			alert("文件类型只能为(cdr或ai或psd)");
  	     			document.getElementById("ofile").outerHTML = document.getElementById("ofile").outerHTML;  
  	     	     }
    	  }
     	
      }